package tests;

import reflect.pojo.Person;

import java.lang.reflect.Field;

/**
 * @author:雷淑娥
 * @Date:2024/12/5 14:15
 * version:1.0
 */
public class Test02 {
    public static void main(String[] args) {
        try {
            //通过反射加载
            Class clz = Class.forName("reflect.pojo.Person");
            Object person = clz.newInstance();

            //获取属性
            Field address = clz.getDeclaredField("address");
            //使用setAccessable方法
            address.setAccessible(true);

            System.out.println("赋值前的address：" + address.get(person));
            address.set(person,"add");
            System.out.println("赋值后的address：" + address.get(person));
        }catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
